package org.example.user.api;

import org.example.common.api.UserInterface;
import org.example.common.pojo.SysUser;
import org.example.user.entity.SysUserEntity;
import org.example.user.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserInterface {

    @Autowired
    private SysUserMapper sysUserMapper;
    @Override
    public SysUser getSysUser(Long userId) {
        SysUserEntity sysUserEntity = sysUserMapper.selectOneById(userId);
        SysUser sysUser = new SysUser();
        sysUser.setUsername(sysUserEntity.getUsername());
        sysUser.setUserId(sysUserEntity.getId());
        sysUser.setUserType(sysUserEntity.getUserType());
        sysUser.setPassword(sysUserEntity.getPassword());
        sysUser.setEmail(sysUserEntity.getEmail());
        sysUser.setMobile(sysUserEntity.getMobile());
        sysUser.setCreateTime(sysUserEntity.getCreatedTime());
        sysUser.setUpdateTime(sysUserEntity.getUpdatedTime());
        sysUser.setRealName(sysUserEntity.getRealName());
        return sysUser;
    }

    @Override
    public void updateUserInfo(SysUser sysUser) {
        SysUserEntity sysUserEntity = sysUserMapper.selectOneById(sysUser.getUserId());
        sysUserEntity.setUsername(sysUser.getUsername());
        sysUserEntity.setUserType(sysUser.getUserType());
        sysUserEntity.setPassword(sysUser.getPassword());
        sysUserEntity.setEmail(sysUser.getEmail());
        sysUserEntity.setMobile(sysUser.getMobile());
        sysUserEntity.setRealName(sysUser.getRealName());
        sysUserMapper.update(sysUserEntity);
    }

}
